package com.sakura.probe.pojo;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author Sakura
 * @since 2020-08-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("pb_topic")
@ApiModel(value="Topic对象", description="帖子相关实体信息")
public class Topic implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "帖子id")
    @TableId(value = "topic_id", type = IdType.AUTO)
    private Long topicId;

    @ApiModelProperty(value = "发帖人id")
    private Long ownerId;

    @ApiModelProperty(value = "帖子类型id")
    private Long topicCategoryId;

    private Long parentCategoryId;

    @ApiModelProperty(value = "标题")
    @Field(analyzer = "ik_max_word",type = FieldType.Text)
    private String topicName;

    @ApiModelProperty(value = "正文")
    private String topicDesc;

    @ApiModelProperty(value = "帖子讨论数量")
    @TableField(exist = false)
    private Integer topicDiscussNum;

    @ApiModelProperty(value = "帖子点赞人数")
    @TableField(exist = false)
    private Integer topicThumbNum;

    @ApiModelProperty(value = "帖子收藏人数")
    @TableField(exist = false)
    private Integer topicCollectionNum;

    @ApiModelProperty(value = "是否可以发布(1-可以发布，0-不能发布)")
    private Integer enableStatus;

    @ApiModelProperty(value = "逻辑删除(0-未删除，1-删除)")
    @TableLogic
    private Integer deleted;

    @ApiModelProperty(value = "是否能评论(1-可以评论，0-不能评论)")
    private Integer enableComment;

    @ApiModelProperty(value = "0-用户 1-管理者")
    private Integer identity;

    private String advice;

    @ApiModelProperty(value = "优先级")
    private Integer priority;

    @ApiModelProperty(value = "0-普通话题 1-轮播图")
    private Integer enableHeadline;

    @ApiModelProperty(value = "发布时间")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date lastEditTime;

    //本人是否有收藏该帖子
    @TableField(exist = false)
    private boolean isCollect;

    //是否有给该帖子点赞
    @TableField(exist = false)
    private boolean isThumb;

    @TableField(exist = false)
    private List<TopicImg> topicImgList;

    @TableField(exist = false)
    private Video video;

    @TableField(exist = false)
    private String topicCategoryName;

    @TableField(exist = false)
    private PersonInfo personInfo;



    public Topic() {

    }

    //初始化数据存储在elasticsearch中
    public Topic(Long topicId,Long topicCategoryId, String topicName, Integer enableStatus ,Date createTime,String topicCategoryName) {
        this.topicId = topicId;
        this.topicCategoryId = topicCategoryId;
        this.topicName = topicName;
        this.enableStatus = enableStatus;
        this.createTime = createTime;
        this.topicCategoryName = topicCategoryName;
    }

    //话题列表中的查询条件构造器
    public Topic(Long topicCategoryId,String topicName) {
        this.topicCategoryId = topicCategoryId;
        if ("".equals(topicName)||null==topicName){
            this.topicName = null;
        }else {
            this.topicName = topicName;
        }

    }
}
